package com.avcdata.aoscustommade.activity;

import android.app.Dialog;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.avcdata.aoscustommade.R;
import com.avcdata.aoscustommade.adapter.MyWheelAdapter;
import com.avcdata.aoscustommade.adapter.SelectMuchAdapter;
import com.avcdata.aoscustommade.bean.DateSelectCategoryBean;
import com.avcdata.aoscustommade.bean.DetailsBean;
import com.avcdata.aoscustommade.bean.HotBrandCumulativeBean;
import com.avcdata.aoscustommade.bean.LocatityCacheData;
import com.avcdata.aoscustommade.bean.TechnologyBean;
import com.avcdata.aoscustommade.main.BaseActivity;
import com.avcdata.aoscustommade.model.CityDatailActivityModel;
import com.avcdata.aoscustommade.presenter.CityDatailActivityPresenter;
import com.avcdata.aoscustommade.receiver.MyReceiver;
import com.avcdata.aoscustommade.utils.AppActivityManager;
import com.avcdata.aoscustommade.utils.MyXDetailValueFormatter;
import com.avcdata.aoscustommade.utils.ScreenUtils;
import com.avcdata.aoscustommade.utils.SharedPreferencesUtils;
import com.avcdata.aoscustommade.utils.TextUitl;
import com.avcdata.aoscustommade.utils.ToastUtils;
import com.avcdata.aoscustommade.view.CityDatailActivityView;
import com.avcdata.aoscustommade.view.MyList_View;
import com.avcdata.avcchart.linechart.combinedchart.AvcCombinedChart;
import com.avcdata.avcchart.linechart.chart.AvcLineCharts;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.CombinedData;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.formatter.IValueFormatter;
import com.github.mikephil.charting.formatter.IndexAxisValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.listener.ChartTouchListener;
import com.github.mikephil.charting.listener.OnChartGestureListener;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.utils.ViewPortHandler;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.wx.wheelview.widget.WheelView;

import org.apache.http.conn.ConnectTimeoutException;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import static com.avcdata.aoscustommade.R.color.blue_title;
import static com.avcdata.aoscustommade.R.id.dialog_cancel;
import static com.avcdata.aoscustommade.R.id.item_checkbox;
import static com.avcdata.aoscustommade.R.id.item_name;
import static com.avcdata.aoscustommade.R.id.item_selecttimetypetitle;

/***
 * 城市信息详情页
 */
public class CityDatail_Activity extends BaseActivity implements OnChartGestureListener, OnChartValueSelectedListener, CityDatailActivityView {

    @ViewInject(R.id.leftImage)
    private ImageView leftImage;
    @ViewInject(R.id.leftText)
    private TextView leftText;
    @ViewInject(R.id.title)
    private TextView title;
    @ViewInject(R.id.rightText)
    private TextView rightText;
    @ViewInject(R.id.rightImage2)
    private ImageView rightImage;

    @ViewInject(R.id.tabtime)
    private View tabtime;
    @ViewInject(R.id.time_start)
    private RelativeLayout time_start;
    @ViewInject(R.id.time_starttext)
    private TextView time_starttext;
    @ViewInject(R.id.time_end)
    private RelativeLayout time_end;
    @ViewInject(R.id.time_endtext)
    private TextView time_endtext;

    @ViewInject(R.id.tab1)
    private TextView tab1;
    @ViewInject(R.id.tab2)
    private TextView tab2;
    @ViewInject(R.id.tab3)
    private TextView tab3;
    @ViewInject(R.id.tab4)
    private TextView tab4;
    @ViewInject(R.id.tab1_btm)
    private View tab1_btm;
    @ViewInject(R.id.tab2_btm)
    private View tab2_btm;
    @ViewInject(R.id.tab3_btm)
    private View tab3_btm;
    @ViewInject(R.id.tab4_btm)
    private View tab4_btm;

    @ViewInject(R.id.selectdatail)
    private View selectdatail;
    @ViewInject(R.id.listview)
    private ListView listview;

    //分类选取
    @ViewInject(R.id.selectequipment_lay)
    private RelativeLayout selectequipment_lay;
    @ViewInject(R.id.selectequipment_text)
    private TextView selectequipment_text;
    @ViewInject(R.id.selectshop_lay)
    private RelativeLayout selectshop_lay;
    @ViewInject(R.id.selectshop_text)
    private TextView selectshop_text;
    @ViewInject(R.id.selectsales_lay)
    private RelativeLayout selectsales_lay;
    @ViewInject(R.id.selectsales_text)
    private TextView selectsales_text;
    @ViewInject(R.id.select_btmlay)
    private LinearLayout select_btmlay;
    @ViewInject(R.id.selectmoney_lay)
    private RelativeLayout selectmoney_lay;
    @ViewInject(R.id.selectmoney_text)
    private TextView selectmoney_text;
    @ViewInject(R.id.selectstandard_lay)
    private RelativeLayout selectstandard_lay;
    @ViewInject(R.id.selectstandard_text)
    private TextView selectstandard_text;

    //异常情况
    @ViewInject(R.id.loadfail)
    private View loadfail;
    //    @ViewInject(R.id.noinfo)
//    private View noinfo;
    @ViewInject(R.id.jiazai_layout)
    private LinearLayout jiazai_layout;
    @ViewInject(R.id.load_fail_layout)
    private LinearLayout load_fail_layout;
    @ViewInject(R.id.content_lay)
    private RelativeLayout content_lay;


    //头部趋势图
    private View headView;
    private View tagView;
    private TextView module_name;
    private TextView module_type;
    private ImageView module_arrows;
    private TextView datial_type;
    private View typeTop50_lay;
    private TextView typeTop50_lay_noinfo;
    private AvcLineCharts linechart_view;
    private MyList_View listview_scroll;
    private AvcCombinedChart combinedChart_View;
    private TextView tab_volume;

    //空数据处理
    private View module1_content;
    private TextView module1_noinfo;
    private TextView module2_noinfo;
    private View single_lay;
    private TextView module3_noinfo;


    //滑动参数
    private int mTouchSlop;
    private float mFirstY;
    private float mCurrentY;
    private int direction;
    private boolean mShow = true;

    private PopupWindow popupWindow;
    private TypeDatailAdapter typeDatailAdapter;
    private String module_typeString;
    private List<TechnologyBean.ReturnValueBean> dataPopup;
    private ArrayList<String> dataPopupCheck;

    private SharedPreferencesUtils sp;

    private int showWeek = 7;
    private ArrayList<String> dataStartDialog;
    private ArrayList<String> dataEndDialog;
    private Dialog dialog;
    private Dialog dialogMuch;

    private ArrayList<String> dataProduct;
    private ArrayList<String> dataChannel;
    private ArrayList<String> dataMeasure;
    private ArrayList<HashMap<String, String>> dataPrice;
    private ArrayList<HashMap<String, String>> dataVolume;

    //显示视图数据
    private ArrayList<HotBrandCumulativeBean.ReturnValueBean> dataSalesOccupancy;
    private List<DetailsBean.ReturnValueBean> dataTOP50type;

    //类型用各种数据
    private String categoryString = "";
    private String cityString = "";
    private String channelNameString = "all";
    private String measureString = "amount";
    private String measureStringTemp = "";
    private ArrayList<String> priceSegmentString = new ArrayList<>();//全部价格段
    private ArrayList<HashMap<String, String>> priceSegmentStringTemp = new ArrayList<>();//全部价格段临时存储
    private ArrayList<String> lowestPriceString = new ArrayList<>();
    private ArrayList<String> highestPriceString = new ArrayList<>();
    private ArrayList<String> dataVolumeString = new ArrayList<>();//全部规格段
    private ArrayList<HashMap<String, String>> dataVolumeStringTemp = new ArrayList<>();//全部规格段临时储存
    private SelectMuchAdapter selectMuchAdapter;

    private boolean isTabTime = true;//选择时间签
    private boolean isWaterHeater = false;//是否是热水器
    private String time_startString;
    private String time_endString;
    private MyReceiver myReceiver;
    private CityDatailActivityPresenter cityDatailActivityPresenter;

    @Override
    public void initView() {
        setContentView(R.layout.activity_citydatail);
        AppActivityManager.getAppManager().addActivity(this);
        ViewUtils.inject(this);

        headView = LayoutInflater.from(this).inflate(R.layout.head_citydatail, null);
//        tagView = LayoutInflater.from(this).inflate(R.layout.tag_type, null);
        listview.addHeaderView(headView);

        linechart_view = (AvcLineCharts) headView.findViewById(R.id.linechart_view);
        listview_scroll = (MyList_View) headView.findViewById(R.id.listview_scroll);
        combinedChart_View = (AvcCombinedChart) headView.findViewById(R.id.combinedChart_View);
        module_name = (TextView) headView.findViewById(R.id.module_name);
        module_type = (TextView) headView.findViewById(R.id.module_type);
        datial_type = (TextView) headView.findViewById(R.id.datial_type);
        module_arrows = (ImageView) headView.findViewById(R.id.module_arrows);
        typeTop50_lay = (View) headView.findViewById(R.id.typeTop50_lay);
        typeTop50_lay_noinfo = (TextView) headView.findViewById(R.id.typeTop50_lay_noinfo);
        tab_volume = (TextView) headView.findViewById(R.id.tab_volume);

        module1_content = (View) headView.findViewById(R.id.module1_content);
        module1_noinfo = (TextView) headView.findViewById(R.id.module1_noinfo);
        module2_noinfo = (TextView) headView.findViewById(R.id.module2_noinfo);
        single_lay = (View) headView.findViewById(R.id.single_lay);
        module3_noinfo = (TextView) headView.findViewById(R.id.module3_noinfo);

//        listview = (ListView) headView.findViewById(R.id.listview);

    }


    @Override
    public void initInstall() {
        sp = new SharedPreferencesUtils(this);
        IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
        myReceiver = new MyReceiver(loadfail);
        this.registerReceiver(myReceiver, filter);

        rightText.setText(getResources().getString(R.string.area_set));
        rightImage.setImageResource(R.mipmap.location);
        rightImage.setVisibility(View.VISIBLE);
        tab3.setText(sp.getNewWeek());
        tab1_btm.setBackgroundResource(R.color.white);
        module_name.setText("全国销额TOP50机型详情");
        module_type.setText("技术筛选");
        cityString = TextUitl.isEmpty(getIntent().getStringExtra("city")) ? "全国" : getIntent().getStringExtra("city").equals("城市") ? "全国" : getIntent().getStringExtra("city");
        categoryString = getIntent().getStringExtra("category");
        if (TextUitl.isEmpty(cityString) || cityString.equals("全国")) {
            title.setText("全国市场");
        } else {
            title.setText(cityString + "详情");
        }
        selectequipment_text.setText(categoryString);
        selectshop_text.setText("全部渠道");
        selectsales_text.setText("销额");
        selectmoney_text.setText("全部价格段");
        selectstandard_text.setText("全部规格段");
        if (categoryString.equals("热水器")) {
            isWaterHeater = true;
            select_btmlay.setVisibility(View.GONE);
        } else {
            isWaterHeater = false;
            select_btmlay.setVisibility(View.VISIBLE);
        }

        cityDatailActivityPresenter = new CityDatailActivityPresenter(this, new CityDatailActivityModel(CityDatail_Activity.this));
    }


    @Override
    public void initData() {
        dataStartDialog = new ArrayList<>();
        dataEndDialog = new ArrayList<>();
        dataPopupCheck = new ArrayList<>();
        ArrayList<String> da = LocatityCacheData.detailData;
        dataProduct = da;
        dataChannel = new ArrayList<>();
        dataChannel.add("全部渠道");
        dataMeasure = new ArrayList<>();
        dataMeasure.add("销额");
        dataMeasure.add("销量");

//        time_startString = sp.getNewWeek();
//        time_endString = sp.getNewWeek();
//        time_starttext.setText(time_startString);
//        time_endtext.setText(time_endString);

        //价格规格相关
        priceSegmentString.add("全部价格段");
        lowestPriceString.add("0");
        highestPriceString.add("99999999");
        dataVolumeString.add("全部");
        load(true);
    }


    private void load(boolean isLoadDate) {
        if (isLoadDate) {
            loadSelectCategory();
        }
        if (measureString.equals("volume")) {
            if (TextUitl.isEmpty(cityString) || cityString.equals("全国")) {
                module_name.setText("全国销量TOP50机型详情");
            } else {
                module_name.setText(cityString + "销量TOP50机型详情");
            }
            datial_type.setText("热门品牌销量占有率趋势");
//            trendtip.setText("热门品牌销量占有率趋势");
        } else {
            if (TextUitl.isEmpty(cityString) || cityString.equals("全国")) {
                module_name.setText("全国销额TOP50机型详情");
            } else {
                module_name.setText(cityString + "销额TOP50机型详情");
            }
            datial_type.setText("热门品牌销额占有率趋势");
//            trendtip.setText("热门品牌销额占有率趋势");
        }

        if (categoryString.equals("热水器")) {
            isWaterHeater = true;
            select_btmlay.setVisibility(View.GONE);
        } else {
            isWaterHeater = false;
            select_btmlay.setVisibility(View.VISIBLE);
        }

        loadDatail();
    }


    private void loading(boolean isFail, boolean isLoading, boolean isNoInfo) {
        if (isFail) {
            if (isLoading) {
                tabtime.setVisibility(View.GONE);
                loadfail.setVisibility(View.GONE);
                load_fail_layout.setVisibility(View.GONE);
                jiazai_layout.setVisibility(View.GONE);
                content_lay.setVisibility(View.GONE);
//                noinfo.setVisibility(View.GONE);
            } else {
                tabtime.setVisibility(View.VISIBLE);
                loadfail.setVisibility(View.VISIBLE);
                load_fail_layout.setVisibility(View.VISIBLE);
                jiazai_layout.setVisibility(View.GONE);
                content_lay.setVisibility(View.GONE);
                if (isNoInfo) {
                    load_fail_layout.setVisibility(View.GONE);
//                    noinfo.setVisibility(View.VISIBLE);
                } else {
//                    noinfo.setVisibility(View.GONE);
                }

            }
        } else {
//            noinfo.setVisibility(View.GONE);
            if (isLoading) {
                tabtime.setVisibility(View.GONE);
                loadfail.setVisibility(View.VISIBLE);
                load_fail_layout.setVisibility(View.GONE);
                jiazai_layout.setVisibility(View.VISIBLE);
                content_lay.setVisibility(View.GONE);
            } else {
                tabtime.setVisibility(View.VISIBLE);
                loadfail.setVisibility(View.GONE);
                load_fail_layout.setVisibility(View.GONE);
                jiazai_layout.setVisibility(View.GONE);
                content_lay.setVisibility(View.VISIBLE);
            }
        }
    }


    private void loadingTimeout() {
        tabtime.setVisibility(View.VISIBLE);
        loadfail.setVisibility(View.GONE);
        load_fail_layout.setVisibility(View.GONE);
        jiazai_layout.setVisibility(View.GONE);
        content_lay.setVisibility(View.GONE);
    }


    @Override
    public void evenControl() {
        initTouchListener();
        leftImage.setOnClickListener(this);
        leftText.setOnClickListener(this);
        rightText.setOnClickListener(this);
        rightImage.setOnClickListener(this);
        tab1.setOnClickListener(this);
        tab2.setOnClickListener(this);
        tab3.setOnClickListener(this);
        tab4.setOnClickListener(this);
        time_start.setOnClickListener(this);
        time_end.setOnClickListener(this);
        selectequipment_lay.setOnClickListener(this);
        selectshop_lay.setOnClickListener(this);
        selectsales_lay.setOnClickListener(this);
        selectmoney_lay.setOnClickListener(this);
        selectstandard_lay.setOnClickListener(this);
        module_type.setOnClickListener(this);
        module_arrows.setOnClickListener(this);

    }


    /**
     * 获取产品类型日期等
     */
    private void loadSelectCategory() {
        loading(false, true, false);
        cityDatailActivityPresenter.loadSelectCategory("yearWeeks", 51);

    }

    //获取产品类型日期成功
    @Override
    public void loadSelectCategorySuccess(DateSelectCategoryBean bean) {
        if (bean != null) {
            boolean success = bean.isSuccess();
            String message = bean.getMessage();
            List<DateSelectCategoryBean.ReturnValueBean> returnValue = bean.getReturnValue();
            if (success) {
                if (returnValue != null && returnValue.size() > 0) {
                    for (int i = 0; i < returnValue.size(); i++) {
                        dataStartDialog.add(returnValue.get(i).getYear_week());
                        dataEndDialog.add(returnValue.get(i).getYear_week());
                    }
                    time_endString = sp.getNewWeek();
                    time_endtext.setText(time_endString);
                    time_startString = getWeek(8);
                    time_starttext.setText(time_startString);
                } else {
                    loadedType(false, message, -1);
                }
            }
        } else {
            loadedType(false, "", -1);
        }
    }

    //获取产品类型日期失败
    @Override
    public void loadSelectCategoryFailure() {
        loadedType(false, "", -1);
    }

    //获取产品类型日期失败
    @Override
    public void loadSelectCategoryFailure(Throwable throwable) {
        if (throwable instanceof ConnectTimeoutException ||
                throwable instanceof SocketTimeoutException) {
            ToastUtils.showShort(CityDatail_Activity.this, "网络请求错误");
            loadingTimeout();
        }
    }


    @SuppressWarnings("deprecation")
    @Override
    public void onClickEvent(View view) {
        switch (view.getId()) {
            case R.id.leftImage:
            case R.id.leftText:
                AppActivityManager.getAppManager().finishActivity(this);
                break;
            case R.id.rightText:
            case R.id.rightImage:
                Intent intent = new Intent(this, SelectBigArea_Activity.class);
                startActivity(intent);
                break;
            case R.id.tab1:
                tab1_btm.setBackgroundResource(R.color.white);
                tab2_btm.setBackgroundResource(blue_title);
                tab3_btm.setBackgroundResource(blue_title);
                tab4_btm.setBackgroundResource(blue_title);
                showWeek = 7;
                resetTimeShow(1);
                load(false);
                break;
            case R.id.tab2:
                tab1_btm.setBackgroundResource(blue_title);
                tab2_btm.setBackgroundResource(R.color.white);
                tab3_btm.setBackgroundResource(blue_title);
                tab4_btm.setBackgroundResource(blue_title);
                showWeek = 3;
                resetTimeShow(2);
                load(false);
                break;
            case R.id.tab3:
                tab1_btm.setBackgroundResource(blue_title);
                tab2_btm.setBackgroundResource(blue_title);
                tab3_btm.setBackgroundResource(R.color.white);
                tab4_btm.setBackgroundResource(blue_title);
                showWeek = 0;
                resetTimeShow(3);
                load(false);
                break;
            case R.id.tab4:
                tab1_btm.setBackgroundResource(blue_title);
                tab2_btm.setBackgroundResource(blue_title);
                tab3_btm.setBackgroundResource(blue_title);
                tab4_btm.setBackgroundResource(R.color.white);
                showWeek = TextUitl.getSurplusWeek(52, sp.getNewWeek());
                resetTimeShow(4);
                load(false);
                break;
            case R.id.time_start:
            case R.id.time_end:
                showDialogSelect(false, 0);
                if (dialog != null && !dialog.isShowing()) {
                    dialog.show();
                }
                break;
            case R.id.selectequipment_lay:
                showDialogSelect(true, 1);
                if (dialog != null && !dialog.isShowing()) {
                    dialog.show();
                }
                break;
            case R.id.selectshop_lay:
                showDialogSelect(true, 2);
                if (dialog != null && !dialog.isShowing()) {
                    dialog.show();
                }
                break;
            case R.id.selectsales_lay:
                showDialogSelect(true, 3);
                if (dialog != null && !dialog.isShowing()) {
                    dialog.show();
                }
                break;
            case R.id.selectmoney_lay:
                showDialogSelectMuch(0);
                if (dialogMuch != null && !dialogMuch.isShowing()) {
                    dialogMuch.show();
                }
                break;

            case R.id.selectstandard_lay:
                showDialogSelectMuch(1);
                if (dialogMuch != null && !dialogMuch.isShowing()) {
                    dialogMuch.show();
                }
                break;
            case R.id.module_type:
            case R.id.module_arrows:
                if (popupWindow != null && popupWindow.isShowing()) {
                    popupWindow.dismiss();
                } else {
                    popupWindow.showAsDropDown(view);
                }


                break;
        }

    }


    private void resetTimeShow(int num) {
        isTabTime = true;
//        measureString = "volume";
        switch (num) {
            case 1:
                time_startString = getWeek(8);
                time_endString = sp.getNewWeek();
                break;
            case 2:
                time_startString = getWeek(4);
                time_endString = sp.getNewWeek();
                break;
            case 3:
                time_startString = sp.getNewWeek();
                time_endString = sp.getNewWeek();
                break;
            case 4:
                time_startString = getWeek(TextUitl.getSurplusWeek(52, sp.getNewWeek()) + 1);
                time_endString = sp.getNewWeek();
                break;
        }
//        Log.e("string","-------------time_startString="+time_startString);
//        Log.e("string","-------------time_endString="+time_endString);
        time_starttext.setText(time_startString);
        time_endtext.setText(time_endString);
    }

    private String getWeek(int num) {
        if (TextUitl.isEmpty(sp.getNewWeek())) {
            return dataStartDialog.get(0);
        }
        String[] arrayNewWeek = sp.getNewWeek().split("W");
        int temp = Integer.valueOf(arrayNewWeek[1]) - num;
//        Log.e("string","-------------temp="+temp);
        if (temp > 0) {
            return arrayNewWeek[0] + "W" + TextUitl.format00((temp + 1) + "");
        } else {
            return Integer.valueOf(arrayNewWeek[0]) + "W" + "01";
        }
    }


    //单选dialog
    private void showDialogSelect(boolean isSingle, final int dialogNum) {
        //0、时间
        //1、电器类型
        //2、大连锁
        //3、销量
        View view = LayoutInflater.from(CityDatail_Activity.this).inflate(R.layout.dialog_single, null);
        dialog = new Dialog(CityDatail_Activity.this, R.style.DialogBlack);
        Window window = dialog.getWindow();
        window.setContentView(view);
        window.setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        window.setGravity(Gravity.CENTER);

        final TextView dialog_title1 = (TextView) view.findViewById(R.id.dialog_title1);
        TextView dialog_title2 = (TextView) view.findViewById(R.id.dialog_title2);
        final WheelView wheelview_single1 = (WheelView) view.findViewById(R.id.wheelview_single1);
        final WheelView wheelview_single2 = (WheelView) view.findViewById(R.id.wheelview_single2);
        dialog_title2.setText("结束时间");
        if (isSingle) {
            dialog_title2.setVisibility(View.GONE);
            wheelview_single2.setVisibility(View.GONE);
        } else {
            dialog_title2.setVisibility(View.VISIBLE);
            wheelview_single2.setVisibility(View.VISIBLE);
            wheelview_single2.setWheelData(dataEndDialog);
            wheelview_single2.setSelection(getSelectPosition(dataEndDialog, time_endString));
            wheelview_single2.setWheelSize(3);
            wheelview_single2.setWheelAdapter(new MyWheelAdapter(this));
            wheelview_single2.setLoop(false);
            wheelview_single2.setWheelClickable(false);

        }
        wheelview_single1.setSkin(WheelView.Skin.None);
        wheelview_single2.setSkin(WheelView.Skin.None);
        WheelView.WheelViewStyle style = new WheelView.WheelViewStyle();
        style.selectedTextColor = Color.RED;
        style.selectedTextSize = 20;
        style.textColor = Color.BLACK;
        wheelview_single1.setStyle(style);
        wheelview_single2.setStyle(style);
        wheelview_single1.setLoop(false);
        wheelview_single1.setWheelClickable(false);
        switch (dialogNum) {
            case 0:
                dialog_title1.setText("开始时间");
                wheelview_single1.setWheelData(dataStartDialog);
                wheelview_single1.setSelection(getSelectPosition(dataStartDialog, time_startString));
                wheelview_single1.setWheelSize(3);
                wheelview_single1.setWheelAdapter(new MyWheelAdapter(this));
                break;
            case 1:
                dialog_title1.setText("选择电器类型");
                wheelview_single1.setWheelData(dataProduct);
                wheelview_single1.setSelection(getSelectPosition(dataProduct, categoryString));
                wheelview_single1.setWheelSize(3);
                wheelview_single1.setWheelAdapter(new MyWheelAdapter(this));
                break;
            case 2:
                dialog_title1.setText("选择渠道");
                wheelview_single1.setWheelData(dataChannel);
                wheelview_single1.setSelection(getSelectPosition(dataChannel, channelNameString));
                wheelview_single1.setWheelSize(3);
                wheelview_single1.setWheelAdapter(new MyWheelAdapter(this));
                break;
            case 3:
                dialog_title1.setText("选择销售状况");
                wheelview_single1.setWheelData(dataMeasure);
                wheelview_single1.setSelection(getSelectPosition(dataMeasure, measureStringTemp));
                wheelview_single1.setWheelSize(3);
                wheelview_single1.setWheelAdapter(new MyWheelAdapter(this));
                break;
            default:
                load(false);
                break;
        }

        view.findViewById(dialog_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (dialog != null && dialog.isShowing()) {
                    dialog.dismiss();
                }
            }
        });

        view.findViewById(R.id.dialog_ensure).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                select_btmlay.setVisibility(View.VISIBLE);
                switch (dialogNum) {
                    case 0:
                        if (TextUitl.isStartThanEndWeek(dataStartDialog.get(wheelview_single1.getCurrentPosition()), dataEndDialog.get(wheelview_single2.getCurrentPosition()))) {
                            ToastUtils.showShort(CityDatail_Activity.this, "开始时间不能大于结束时间");
                            return;
                        }
                        isTabTime = false;
                        time_startString = dataStartDialog.get(wheelview_single1.getCurrentPosition());
                        time_endString = dataEndDialog.get(wheelview_single2.getCurrentPosition());
                        time_starttext.setText(time_startString);
                        time_endtext.setText(time_endString);
                        showWeek = 51;
                        tab1_btm.setBackgroundResource(R.color.blue_title);
                        tab2_btm.setBackgroundResource(R.color.blue_title);
                        tab3_btm.setBackgroundResource(R.color.blue_title);
                        tab4_btm.setBackgroundResource(R.color.blue_title);

                        int tempSurplusWeek = TextUitl.getSurplusWeek(52, sp.getNewWeek());
                        if (TextUitl.getStartEndWeek(time_startString, time_endString) == tempSurplusWeek && sp.getNewWeek().equals(time_endString)) {
                            tab4_btm.setBackgroundResource(R.color.white);
                        }
                        if (sp.getNewWeek().equals(time_endString)) {
                            switch (TextUitl.getStartEndWeek(time_startString, time_endString)) {
                                case 0:
                                    tab3_btm.setBackgroundResource(R.color.white);
                                    tab4_btm.setBackgroundResource(R.color.blue_title);
                                    break;
                                case 3:
                                    tab2_btm.setBackgroundResource(R.color.white);
                                    tab4_btm.setBackgroundResource(R.color.blue_title);
                                    break;
                                case 7:
                                    tab1_btm.setBackgroundResource(R.color.white);
                                    tab4_btm.setBackgroundResource(R.color.blue_title);
                                    break;
                                default:
                                    break;
                            }
                        }
                        break;
                    case 1:
                        priceSegmentString.clear();
                        lowestPriceString.clear();
                        highestPriceString.clear();
                        dataVolumeString.clear();
                        priceSegmentString.add("全部价格段");
                        lowestPriceString.add("0");
                        highestPriceString.add("99999999");
                        dataVolumeString.add("全部");

                        selectmoney_text.setText("全部价格段");
                        selectstandard_text.setText("全部规格段");
                        categoryString = dataProduct.get(wheelview_single1.getCurrentPosition());
                        selectequipment_text.setText(categoryString);
                        module_type.setText("技术筛选");
                        dataPopupCheck.clear();
//                        if (dataProduct.get(wheelview_single1.getCurrentPosition()).equals("热水器")) {
//                            isWaterHeater = true;
//                            select_btmlay.setVisibility(View.GONE);
//                        } else {
//                            isWaterHeater = false;
//                            select_btmlay.setVisibility(View.VISIBLE);
//                        }
                        break;
                    case 2:
                        channelNameString = dataChannel.get(wheelview_single1.getCurrentPosition());
                        selectshop_text.setText(channelNameString);
                        break;
                    case 3:
                        measureString = dataMeasure.get(wheelview_single1.getCurrentPosition());
                        measureStringTemp = measureString;
                        selectsales_text.setText(measureString);
                        if (dataMeasure.get(wheelview_single1.getCurrentPosition()).equals("销额")) {
                            measureString = "amount";
                        } else {
                            measureString = "volume";
                        }
                        break;
                }
                load(false);
                if (dialog != null && dialog.isShowing()) {
                    dialog.dismiss();
                }
            }
        });


    }

    private int getSelectPosition(ArrayList<String> dataTemp, String stringTemp) {
        int temp = 0;
        for (int i = 0; i < dataTemp.size(); i++) {
            if (dataTemp.get(i).equals(stringTemp)) {
                temp = i;
            }
        }
        return temp;
    }

    private ArrayList<HashMap<String, String>> checkMuchData(ArrayList<HashMap<String, String>> data, ArrayList<String> temp, boolean isPrice) {
        ArrayList<HashMap<String, String>> dataTmep = data;
//        for (int i = 0; i < dataTmep.size(); i++) {
//            Log.e("string", "--------------判断数据长度--------" + dataTmep.get(i).get("isCheck"));
//        }
        if (temp.size() == 1) {
            if (isPrice) {
                if (dataTmep.get(0).get("priceSegment").equals(temp.get(0))) {
                    for (int i = 0; i < dataTmep.size(); i++) {
                        dataTmep.get(i).put("isCheck", "0");
                    }
                } else {
                    for (int i = 0; i < dataTmep.size(); i++) {
                        if (dataTmep.get(i).get("priceSegment").equals(temp.get(0))) {
                            dataTmep.get(i).put("isCheck", "0");
                        }
                    }
                }
            } else {
                if (dataTmep.get(0).get("name").equals(temp.get(0))) {
                    for (int i = 0; i < dataTmep.size(); i++) {
                        dataTmep.get(i).put("isCheck", "0");
                    }
                } else {
                    for (int i = 0; i < dataTmep.size(); i++) {
                        if (dataTmep.get(i).get("name").equals(temp.get(0))) {
                            dataTmep.get(i).put("isCheck", "0");
                        }
                    }
                }
            }
        } else {
            for (int i = 0; i < dataTmep.size(); i++) {
                for (int j = 0; j < temp.size(); j++) {
                    if (isPrice) {
                        if (dataTmep.get(i).get("priceSegment").equals(temp.get(j))) {
                            dataTmep.get(i).put("isCheck", "0");
                        }
                    } else {
                        if (dataTmep.get(i).get("name").equals(temp.get(j))) {
                            dataTmep.get(i).put("isCheck", "0");
                        }
                    }

                }
            }
        }

        return dataTmep;

    }


    //多选dialog
    private void showDialogSelectMuch(final int dialogNum) {
        View view = LayoutInflater.from(CityDatail_Activity.this).inflate(R.layout.dialog_much, null);
        dialogMuch = new Dialog(CityDatail_Activity.this, R.style.DialogBlack);
        dialogMuch.setCanceledOnTouchOutside(false);//使除了dialog以外的地方不能被点击
        Window window = dialogMuch.getWindow();
        window.setContentView(view);
        window.setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        window.setGravity(Gravity.CENTER);
        final TextView dialogmuch_title = (TextView) view.findViewById(R.id.dialogmuch_title);
        ListView listview = (ListView) view.findViewById(R.id.listview);
//        listview.setItemsCanFocus(true);
//        listview.setFocusableInTouchMode(true);
        TextView dialog_cancel = (TextView) view.findViewById(R.id.dialog_cancel);
        TextView dialog_ensure = (TextView) view.findViewById(R.id.dialog_ensure);

//        if (isSelectCategory) {
//            priceSegmentStringTemp.clear();
//            dataVolumeStringTemp.clear();
//        }

        switch (dialogNum) {
            case 0:
                dialogmuch_title.setText("选择价格段");
                selectMuchAdapter = new SelectMuchAdapter(CityDatail_Activity.this, checkMuchData(dataPrice, priceSegmentString, true), 0);
                listview.setAdapter(selectMuchAdapter);
                break;
            case 1:
                dialogmuch_title.setText("选择容积段");
                selectMuchAdapter = new SelectMuchAdapter(CityDatail_Activity.this, checkMuchData(dataVolume, dataVolumeString, false), 1);
                listview.setAdapter(selectMuchAdapter);
                break;
        }
        selectMuchAdapter.notifyDataSetChanged();

        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                CheckBox cBox = (CheckBox) view.findViewById(item_checkbox);
                if (cBox.isChecked()) {
                    cBox.setChecked(false);
                } else {
                    cBox.setChecked(true);
                }
                selectMuchAdapter.notifyDataSetChanged();
                switch (dialogNum) {
                    case 0:
                        if (position == 0 && (cBox.isChecked())) {
                            //如果是选中 全选  就把所有的都选上 然后更新,点击获得全选
                            for (int i = 0; i < dataPrice.size(); i++) {
                                dataPrice.get(i).put("isCheck", "0");
                            }
                        } else if (position == 0 && (!cBox.isChecked())) {
                            //如果是取消全选 就把所有的都取消 然后更新，点击取消全部选择
                            for (int i = 0; i < dataPrice.size(); i++) {
                                dataPrice.get(i).put("isCheck", "1");
                            }
                        }
                        selectMuchAdapter.notifyDataSetChanged();
                        if (position != 0 && (!cBox.isChecked())) {
                            // 如果把其它的选项取消   把全选取消
                            dataPrice.get(0).put("isCheck", "1");
                            dataPrice.get(position).put("isCheck", "1");
                            selectMuchAdapter.notifyDataSetChanged();
                        } else if (position != 0 && (cBox.isChecked())) {
                            //如果选择其它的选项，看是否全部选择
                            //先把该选项选中 设置为true
                            dataPrice.get(position).put("isCheck", "0");
                            int a = 0;
                            for (int i = 1; i < dataPrice.size(); i++) {
                                if (dataPrice.get(i).get("isCheck").equals("1")) {
                                    //如果有一个没选中  就不是全选 直接跳出循环
                                    break;
                                } else {
                                    //计算有多少个选中的
                                    a++;
                                    if (a == dataPrice.size() - 1) {
                                        //如果选项都选中，就把全选 选中，然后更新
                                        dataPrice.get(0).put("isCheck", "0");
                                        selectMuchAdapter.notifyDataSetChanged();
                                    }
                                }
                            }


                        }


                        break;
                    case 1:
                        if (position == 0 && (cBox.isChecked())) {
                            //如果是选中 全选  就把所有的都选上 然后更新
                            for (int i = 0; i < dataVolume.size(); i++) {
                                dataVolume.get(i).put("isCheck", "0");
                            }
                        } else if (position == 0 && (!cBox.isChecked())) {
                            //如果是取消全选 就把所有的都取消 然后更新
                            for (int i = 0; i < dataVolume.size(); i++) {
                                dataVolume.get(i).put("isCheck", "1");
                            }
                        }
                        selectMuchAdapter.notifyDataSetChanged();

                        if (position != 0 && (!cBox.isChecked())) {
                            // 如果把其它的选项取消   把全选取消
                            dataVolume.get(0).put("isCheck", "1");
                            dataVolume.get(position).put("isCheck", "1");
                            selectMuchAdapter.notifyDataSetChanged();
                        } else if (position != 0 && (cBox.isChecked())) {
                            //如果选择其它的选项，看是否全部选择
                            //先把该选项选中 设置为true
                            dataVolume.get(position).put("isCheck", "0");
                            int a = 0;
                            for (int i = 1; i < dataVolume.size(); i++) {
                                if (dataVolume.get(i).get("isCheck").equals("1")) {
                                    //如果有一个没选中  就不是全选 直接跳出循环
                                    break;
                                } else {
                                    //计算有多少个选中的
                                    a++;
                                    if (a == dataVolume.size() - 1) {
                                        //如果选项都选中，就把全选 选中，然后更新
                                        dataVolume.get(0).put("isCheck", "0");
                                        selectMuchAdapter.notifyDataSetChanged();
                                    }
                                }
                            }

                        }
                        break;
                }

            }
        });


        dialog_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (dialogMuch != null && dialogMuch.isShowing()) {
                    dialogMuch.dismiss();
                }
            }
        });

        dialog_ensure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String indexString = "";
                switch (dialogNum) {
                    case 0:
                        priceSegmentString.clear();
                        lowestPriceString.clear();
                        highestPriceString.clear();
                        if (dataPrice.get(0).get("isCheck").equals("0")) {
                            priceSegmentString.add(dataPrice.get(0).get("priceSegment"));
                            lowestPriceString.add(dataPrice.get(0).get("lowestPrice"));
                            highestPriceString.add(dataPrice.get(0).get("highestPrice"));
                            selectmoney_text.setText("全部价格段");
                        } else {
                            for (int i = 0; i < dataPrice.size(); i++) {
                                if (dataPrice.get(i).get("isCheck").equals("0")) {
                                    indexString = dataPrice.get(i).get("priceSegment");
                                    priceSegmentString.add(dataPrice.get(i).get("priceSegment"));
                                    lowestPriceString.add(dataPrice.get(i).get("lowestPrice"));
                                    highestPriceString.add(dataPrice.get(i).get("highestPrice"));
                                }
                            }
                            if (priceSegmentString.size() >= 2) {
                                selectmoney_text.setText("多选");
                            } else {
                                if (TextUitl.isEmpty(indexString)) {
                                    priceSegmentString.add(dataPrice.get(0).get("priceSegment"));
                                    lowestPriceString.add(dataPrice.get(0).get("lowestPrice"));
                                    highestPriceString.add(dataPrice.get(0).get("highestPrice"));
                                    selectmoney_text.setText("全部价格段");
                                } else {
                                    selectmoney_text.setText(indexString);
                                }
                            }
                        }
                        break;
                    case 1:
                        dataVolumeString.clear();
                        if (dataVolume.get(0).get("isCheck").equals("0")) {
                            dataVolumeString.add(dataVolume.get(0).get("name"));
                            selectstandard_text.setText("全部规格段");

                        } else {
                            for (int i = 0; i < dataVolume.size(); i++) {
                                if (dataVolume.get(i).get("isCheck").equals("0")) {
                                    indexString = dataVolume.get(i).get("name");
                                    dataVolumeString.add(dataVolume.get(i).get("name"));
                                }
                            }
                            if (dataVolumeString.size() >= 2) {
                                selectstandard_text.setText("多选");
                            } else {
                                if (TextUitl.isEmpty(indexString)) {
                                    dataVolumeString.add(dataVolume.get(0).get("name"));
                                    selectstandard_text.setText("全部规格段");
                                } else {
                                    selectstandard_text.setText(indexString);
                                }
                            }
                        }
                        break;
                }
                load(false);

                if (dialogMuch != null && dialogMuch.isShowing()) {
                    dialogMuch.dismiss();
                }

            }
        });


    }


    /**
     * 获取价格段+容积段+渠道
     */
    private void loadDatail() {
        loading(false, true, false);
        cityDatailActivityPresenter.loadDatail(categoryString, sp.getUserLimits(), sp.getNewWeek(), cityString, isTabTime, showWeek, time_startString, time_endString, false);
    }

    @Override
    public void loadDatailSuccess(JSONObject jsonObject) {
        ArrayList<String> dataChannelTemp = new ArrayList<>();
        ArrayList<HashMap<String, String>> dataVolumeTemp = new ArrayList<>();
        ArrayList<HashMap<String, String>> dataPriceTemp = new ArrayList<>();
        try {
            if (!TextUitl.isEmpty(jsonObject.toString())) {
                boolean success = jsonObject.getBoolean("success");
                String message = jsonObject.getString("message").trim();
                String returnValue = jsonObject.getString("returnValue").trim();
                if (success && jsonObject.has("returnValue")) {
                    if (!TextUitl.isEmpty(returnValue) && !returnValue.equals("{}")) {
                        JSONObject returnValueObject = new JSONObject(returnValue);
                        String priceSegment = returnValueObject.get("priceSegment").toString().trim();
                        String channel = returnValueObject.get("channel").toString().trim();
                        String productType = returnValueObject.get("productType").toString().trim();
                        if (!TextUitl.isEmpty(priceSegment)) {
                            JSONArray priceSegmentArray = new JSONArray(priceSegment);
                            for (int j = 0, k = priceSegmentArray.length(); j < k; j++) {
                                JSONObject jsonobject = priceSegmentArray.getJSONObject(j);
                                HashMap<String, String> hashMap = new HashMap<>();
                                hashMap.put("priceSegment", jsonobject.get("priceSegment").toString().trim());
                                hashMap.put("lowestPrice", jsonobject.get("lowestPrice").toString().trim());
                                hashMap.put("highestPrice", jsonobject.get("highestPrice").toString().trim());
                                hashMap.put("isCheck", "1");
                                dataPriceTemp.add(hashMap);
                            }
                            dataPrice = dataPriceTemp;

                        }
                        if (!TextUitl.isEmpty(channel)) {
                            JSONArray channelArray = new JSONArray(channel);
                            for (int j = 0, k = channelArray.length(); j < k; j++) {
                                JSONObject jsonobject = channelArray.getJSONObject(j);
                                dataChannelTemp.add(jsonobject.get("name").toString().trim());
                            }
                            dataChannel = dataChannelTemp;
                        }
                        if (!TextUitl.isEmpty(productType)) {
                            JSONArray productTypeArray = new JSONArray(productType);
                            for (int j = 0, k = productTypeArray.length(); j < k; j++) {
                                JSONObject jsonobject = productTypeArray.getJSONObject(j);
                                HashMap<String, String> hashMap = new HashMap<>();
                                hashMap.put("name", jsonobject.get("name").toString().trim());
                                hashMap.put("value", jsonobject.get("value").toString().trim());
                                hashMap.put("isCheck", "1");
                                dataVolumeTemp.add(hashMap);
                            }
                            dataVolume = dataVolumeTemp;
                        }
                        loadedType(true, message, 0);
                    } else {
                        loadedType(false, message, -1);
                    }
                } else {
                    loadedType(false, message, -1);
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void loadDatailFailure() {
        loadedType(false, "", -1);
    }

    @Override
    public void loadDatailFailure(Throwable throwable) {
        if (throwable instanceof ConnectTimeoutException ||
                throwable instanceof SocketTimeoutException) {
            loadingTimeout();
        }
    }


    private JSONObject clearUpJSON(int typeInt, boolean isEndNum) {
        //0、累计销售情况
        //1、热门品牌销售额占率
        //2、史密斯销售走势
        //3、TOP50机型详情
        JSONObject jsonObject = new JSONObject();
        try {
            JSONArray arrayPriceSegment = new JSONArray();//价格段
            for (int i = 0; i < priceSegmentString.size(); i++) {
//                Log.e("string","--------接口请求参数测试priceSegmentString=-------"+priceSegmentString.get(i));
                arrayPriceSegment.put(priceSegmentString.get(i));
                if (isEndNum) {
                    HashMap<String, String> temp = new HashMap<>();
                    temp.put("priceSegment", priceSegmentString.get(i));
                    priceSegmentStringTemp.add(temp);
                }
            }
            jsonObject.put("priceSegment", arrayPriceSegment);
            if (cityString.equals("全国")) {
                jsonObject.put("cityName", "all");
            } else {
                jsonObject.put("cityName", cityString);
            }

            jsonObject.put("brand", "A.O.史密斯");
            jsonObject.put("category", categoryString);
            jsonObject.put("channel", channelNameString);
            JSONArray arrayLowestPrice = new JSONArray();//低价格
            for (int i = 0; i < lowestPriceString.size(); i++) {
                arrayLowestPrice.put(lowestPriceString.get(i));
            }
            jsonObject.put("lowestPrice", arrayLowestPrice);
            JSONArray arrayHighestPrice = new JSONArray();//高价格
            for (int i = 0; i < highestPriceString.size(); i++) {
                arrayHighestPrice.put(highestPriceString.get(i));
            }
            jsonObject.put("highestPrice", arrayHighestPrice);
            JSONArray arrayProductType = new JSONArray();//产品类型
            for (int i = 0; i < dataVolumeString.size(); i++) {
                if (dataVolumeString.get(i).equals("全部")) {
                    arrayProductType.put("all");
                } else {
                    arrayProductType.put(dataVolumeString.get(i));
                }
                if (isEndNum) {
                    HashMap<String, String> temp = new HashMap<>();
                    temp.put("name", dataVolumeString.get(i));
                    dataVolumeStringTemp.add(temp);
                }
            }
            jsonObject.put("productType", arrayProductType);

            if (typeInt == 0) {
                if (isTabTime) {
                    jsonObject.put("lastWeek", sp.getNewWeek());
                    jsonObject.put("lastWeekCount", showWeek);
                } else {
//                    Log.e("string","--------接口请求参数测试time_startString=-------"+time_startString);
//                    Log.e("string","--------接口请求参数测试time_endString=-------"+time_endString);
//                    Log.e("string","--------接口请求参数测试TextUitl.getStartEndWeek(time_startString, time_endString)=-------"+TextUitl.getStartEndWeek(time_startString, time_endString));
                    jsonObject.put("lastWeek", time_endString);
                    jsonObject.put("lastWeekCount", TextUitl.getStartEndWeek(time_startString, time_endString));
                }
            } else if (typeInt == 1) {
                if (isTabTime) {
                    jsonObject.put("lastWeek", sp.getNewWeek());
                    jsonObject.put("lastWeekCount", showWeek);
                } else {
                    jsonObject.put("lastWeek", time_endString);
                    jsonObject.put("lastWeekCount", TextUitl.getStartEndWeek(time_startString, time_endString));
                }
            } else if (typeInt == 2) {
                if (isTabTime) {
                    jsonObject.put("lastWeek", sp.getNewWeek());
                    jsonObject.put("lastWeekCount", showWeek);
                } else {
                    jsonObject.put("lastWeek", time_endString);
                    jsonObject.put("lastWeekCount", TextUitl.getStartEndWeek(time_startString, time_endString));
                }
            } else {
                if (isTabTime) {
                    jsonObject.put("lastWeek", sp.getNewWeek());
                    jsonObject.put("lastWeekCount", showWeek);
                } else {
                    jsonObject.put("lastWeek", time_endString);
                    jsonObject.put("lastWeekCount", TextUitl.getStartEndWeek(time_startString, time_endString));
                }
                JSONArray arrayProductTechs = new JSONArray();//产品技术
                if (dataPopupCheck.size() != 0) {
                    for (int i = 0, j = dataPopupCheck.size(); i < j; i++) {
                        arrayProductTechs.put(dataPopupCheck.get(i));
//                        Log.e("string", "------产品技术类型-------------" + dataPopupCheck.get(i));
                    }
                }
                jsonObject.put("productTechs", arrayProductTechs);
                jsonObject.put("topModelCount", 50);
            }
            jsonObject.put("salesType", measureString);
            if (sp.getUserLimits().equals("1")) {
                jsonObject.put("channelType", "name");
            } else {
                jsonObject.put("channelType", "type");
            }
//            Log.e("string","--------接口请求参数测试arrayPriceSegment=-------"+arrayPriceSegment.get(0));
//            Log.e("string","--------接口请求参数测试cityName=-------"+cityString);
//            Log.e("string","--------接口请求参数测试lastWeekCount=-------"+showWeek);
//            Log.e("string","--------接口请求参数测试sp.getNewWeek()=-------"+sp.getNewWeek());
//            Log.e("string","--------接口请求参数测试categoryString=-------"+categoryString);
//            Log.e("string","--------接口请求参数测试channelNameString=-------"+channelNameString);
//            Log.e("string","--------接口请求参数测试arrayLowestPrice=-------"+arrayLowestPrice.get(0));
//            Log.e("string","--------接口请求参数测试arrayHighestPrice=-------"+arrayHighestPrice.get(0));
//            Log.e("string","--------接口请求参数测试arrayProductType=-------"+dataVolumeString.get(0));
//            Log.e("string","--------接口请求参数测试salesType=-------"+measureString);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return jsonObject;
    }


    /**
     * 获取热门品牌销售累计情况
     */
    private void loadHotBrandSales() {
        cityDatailActivityPresenter.loadHotBrandSales(clearUpJSON(0, false));
    }

    //获取热门品牌销售累计情况成功
    @Override
    public void loadHotBrandsalesSuccess(Object object) {
        ArrayList<ArrayList<HashMap<String, String>>> trendData = new ArrayList<>();
        ArrayList<String> BrandString = new ArrayList<>();
        JSONObject jsonObject = (JSONObject) object;
        try {
            BrandString.clear();
            if (!TextUitl.isEmpty(jsonObject.toString())) {
                boolean success = jsonObject.getBoolean("success");
                String message = jsonObject.getString("message").trim();
                String secretKey = jsonObject.getString("secretKey").trim();
                if (TextUitl.isEmpty(secretKey) || !sp.getKey().equals(secretKey)) {
                    ToastUtils.showShort(CityDatail_Activity.this, "已在其他设备上登录,请重新登陆");
                    Intent intent = new Intent(CityDatail_Activity.this, Login_Activity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(intent);
                } else {
                    String returnValue = jsonObject.getString("returnValue").trim();
                    if (success && jsonObject.has("returnValue")) {
                        linechart_view.clear();

                        if (!TextUitl.isEmpty(returnValue) || returnValue.equals("{}")) {
                            JSONObject returnValueObject = new JSONObject(returnValue);
                            Iterator iterator = returnValueObject.keys();
                            while (iterator.hasNext()) {
                                String key = iterator.next().toString().trim();
                                String value = returnValueObject.getString(key).trim();
                                BrandString.add(key);
                                JSONArray array = returnValueObject.getJSONArray(key);
                                ArrayList<HashMap<String, String>> tempBrand = new ArrayList<>();
                                for (int a = 0; a < array.length(); a++) {
                                    JSONObject jsonobject = array.getJSONObject(a);
                                    HashMap<String, String> temp = new HashMap<String, String>();
                                    temp.put("key", jsonobject.get("key").toString().trim());
                                    temp.put("value", jsonobject.get("value").toString().trim());
                                    tempBrand.add(temp);
                                }
                                trendData.add(tempBrand);
                            }
//                                    Log.e("data", "---------详情线图数据--------" + BrandString.size());
                            if (BrandString.size() == 0) {
                                tab_volume.setVisibility(View.GONE);
//                                            module1_noinfo.setVisibility(View.VISIBLE);
                            } else {
                                tab_volume.setVisibility(View.VISIBLE);
//                                            module1_noinfo.setVisibility(View.GONE);
                                initNationalTrendData(trendData, BrandString);
                            }
//                                    }
                            loadedType(true, message, 1);
                        }
                    } else {
                        loadedType(false, message, -1);
                    }
                }

            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    //获取热门品牌销售累计情况失败
    @Override
    public void loadHotBrandsalesFailure() {
        loadedType(false, "", -1);
    }

    //获取热门品牌销售累计情况失败
    @Override
    public void loadHotBrandsalesFailure(Throwable throwable) {
        if (throwable instanceof ConnectTimeoutException ||
                throwable instanceof SocketTimeoutException) {
            loadingTimeout();
        }
    }


    @SuppressWarnings("deprecation")//线图设置
    private void initNationalTrendData(ArrayList<ArrayList<HashMap<String, String>>> data, ArrayList<String> key) {
        //设置手势滑动事件
        linechart_view.setOnChartGestureListener(CityDatail_Activity.this);
        //设置数值选择监听
        linechart_view.setOnChartValueSelectedListener(this);
        //后台绘制
        linechart_view.setDrawGridBackground(false);
        //设置描述文本
        linechart_view.getDescription().setEnabled(false);
        // enable touch gestures
        linechart_view.setTouchEnabled(true); // 设置是否可以触摸
        linechart_view.setDragEnabled(true);// 是否可以拖拽
        linechart_view.setScaleEnabled(false);// 是否可以缩放 x和y轴, 默认是true
        linechart_view.setPinchZoom(false);  //设置x轴和y轴能否同时缩放。默认是否
        linechart_view.setDoubleTapToZoomEnabled(false);//设置是否可以通过双击屏幕放大图表。默认是true
        linechart_view.setHighlightPerDragEnabled(false);//能否拖拽高亮线(数据点与坐标的提示线)，默认是true
        linechart_view.setDragDecelerationEnabled(false);//拖拽滚动时，手放开是否会持续滚动，默认是true（false是拖到哪是哪，true拖拽之后还会有缓冲）
        linechart_view.setDragDecelerationFrictionCoef(0.99f);//与上面那个属性配合，持续滚动时的速度快慢，[0,1) 0代表立即停止。

        //如果禁用,扩展可以在x轴和y轴分别完成
        linechart_view.setPinchZoom(false);
//        linechart_view.setBackgroundResource(R.color.white);
        // 是否在折线图上添加边框
        linechart_view.setDrawBorders(false);
        linechart_view.setNoDataText("没有相关数据");

        if (data.size() != 0) {
            linechart_view.moveViewToX(getWeekXCoord(data).size());
        }

        //设置X轴
        XAxis xAxis = linechart_view.getXAxis();
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        xAxis.setTextSize(8f);
        xAxis.setTextColor(getResources().getColor(R.color.text_color));
        xAxis.setDrawAxisLine(true);
        xAxis.setDrawGridLines(false);
        xAxis.setAxisMinimum(0f);
        xAxis.setGranularity(1f);
        xAxis.setAvoidFirstLastClipping(true);

        if (data.size() != 0) {
            xAxis.setValueFormatter(new MyXDetailValueFormatter(getWeekXCoord(data)));
        }

        YAxis leftAxis = linechart_view.getAxis(YAxis.AxisDependency.LEFT);//确定表示图表的侧面
        linechart_view.getAxisRight().setEnabled(false);
        leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);
        leftAxis.setTextSize(8f);
        leftAxis.setTextColor(getResources().getColor(R.color.text_color));
//        leftAxis.setDrawZeroLine(true);
        leftAxis.setDrawAxisLine(true);
        leftAxis.setDrawGridLines(true);
        leftAxis.enableGridDashedLine(2f, 10f, 1f);
        if (data.size() != 0) {
            //y轴最小
            leftAxis.setAxisMinValue(getMinYValue(data, key));
            //y轴最大
            leftAxis.setAxisMaxValue(getMaxYValue(data, key));

        }
        // 限制数据(而不是背后的线条勾勒出了上面)
        leftAxis.setDrawLimitLinesBehindData(true);
        // 设置比例图标示，就是那个一组y的value的
        Legend mLegend = linechart_view.getLegend();
        mLegend.setPosition(Legend.LegendPosition.ABOVE_CHART_CENTER);
        mLegend.setForm(Legend.LegendForm.LINE);// 样式
        mLegend.setFormSize(8f);// 字体
        mLegend.setWordWrapEnabled(true);
        mLegend.setTextColor(Color.DKGRAY);// 颜色
//        mLegend.setYEntrySpace(2f);
//
//        Matrix matrix = new Matrix();
//        if (getWeekXCoord(data).size() <= 4) {
//            // x轴缩放1.5倍
//            matrix.postScale(1f, 1f);
//        } else {
//            matrix.postScale(getWeekXCoord(data).size() / 4, 1f);//根据数据设置比例
//        }
//        // 在图表动画显示之前进行缩放
//        linechart_view.getViewPortHandler().refresh(matrix, linechart_view, false);

        //设置数据
        if (data.size() != 0) {
            trendDataAmend(data, key);
//            Log.e("string", "-------星期数--------------" + getWeekXCoord(data).size());
            linechart_view.setVisibleXRangeMinimum(4);
            linechart_view.setVisibleXRangeMaximum(4);
            linechart_view.resetViewPortOffsets();  //重新设置图表显示的偏移量，自动计算,可取消上面的那个操作
//
        }

        //默认动画
//        linechart_view.animateXY(1000,1000);

        linechart_view.invalidate();

    }


    //获取星期数
    private ArrayList<String> getWeekXCoord(ArrayList<ArrayList<HashMap<String, String>>> data) {
        ArrayList<String> temp = new ArrayList<>();
        for (int a = 0, b = data.get(0).size(); a < b; a++) {
            HashMap<String, String> hashMap = data.get(0).get(a);
            String key = hashMap.get("key").toString().trim();
            String value = hashMap.get("value").toString().trim();
            temp.add(key);
        }
        return temp;
    }


    //获取最小值
    private float getMinYValue(ArrayList<ArrayList<HashMap<String, String>>> data, ArrayList<String> keyBrand) {
        float endValue = -2f;
        for (int i = 0; i < keyBrand.size(); i++) {
            for (int a = 0, b = data.get(i).size(); a < b; a++) {
                HashMap<String, String> hashMap = data.get(i).get(a);
                String key = hashMap.get("key").toString().trim();
                String value = hashMap.get("value").toString().trim();
                if (!TextUitl.isEmpty(value)) {
                    float tempValue = Float.valueOf(value);
                    endValue = tempValue < endValue ? tempValue : endValue;
                }
            }
        }
        return Math.round(endValue - 2f);
    }


    //获取最大值
    private float getMaxYValue(ArrayList<ArrayList<HashMap<String, String>>> data, ArrayList<String> keyBrand) {
        float endValue = 20f;
        for (int i = 0; i < keyBrand.size(); i++) {
            for (int a = 0, b = data.get(i).size(); a < b; a++) {
                HashMap<String, String> hashMap = data.get(i).get(a);
                String key = hashMap.get("key").toString().trim();
                String value = hashMap.get("value").toString().trim();
                if (!TextUitl.isEmpty(value)) {
                    float tempValue = Float.valueOf(value);
                    endValue = tempValue > endValue ? tempValue : endValue;
                }
            }

        }
        return Math.round(endValue + 10f);
    }


    //线性图数据
    @SuppressWarnings("deprecation")
    private void trendDataAmend(ArrayList<ArrayList<HashMap<String, String>>> data, ArrayList<String> keyBrand) {
        ArrayList<String> xString = new ArrayList<>();//X坐标的值
        ArrayList<ILineDataSet> mLineDataSets = new ArrayList<>();
        for (int i = 0; i < keyBrand.size(); i++) {
            ArrayList<Entry> yString = new ArrayList<>();//Y坐标的值
            for (int a = 0, b = data.get(i).size(); a < b; a++) {
//                Log.e("string", "------详情页keyBrand.get(i)------" + keyBrand.get(i));
                HashMap<String, String> hashMap = data.get(i).get(a);
                String key = hashMap.get("key").toString().trim();
                String value = hashMap.get("value").toString().trim();
                xString.add(key);
                if (TextUitl.isEmpty(value)) {
//                    if (data.get(i).size() < 4) {
                    yString.add(new Entry(a + 1, 0));
//                    } else {
//                        yString.add(new Entry(a , 0));
//                    }
                } else {
//                    if (data.get(i).size() < 4) {
                    yString.add(new Entry(a + 1, TextUitl.retainTwoDecimalsFloat(value)));
//                    } else {
//                        yString.add(new Entry(a, TextUitl.retainTwoDecimalsFloat(value)));
//                    }
                }

            }
            // y轴数据集
            LineDataSet mLineDataSet = new LineDataSet(yString, keyBrand.get(i));

            mLineDataSet.setDrawValues(false);
            // 线宽
            mLineDataSet.setLineWidth(1.0f);
            // 显示的圆形大小
            mLineDataSet.setCircleSize(2.0f);
            mLineDataSet.setDrawCircleHole(true);
            // 折线的颜色
            mLineDataSet.setColor(TextUitl.getColor().get(i));
//            mLineDataSet.setColors(TextUitl.getColor());
            // 圆球的颜色
            mLineDataSet.setCircleColor(TextUitl.getColor().get(i));
//            mLineDataSet.setCircleColors(TextUitl.getColor());
            // 填充曲线下方的区域，红色，半透明。
            mLineDataSet.setDrawFilled(false);
            mLineDataSet.setFillAlpha(40);
            mLineDataSet.setFillColor(TextUitl.getColor().get(i));
            mLineDataSets.add(mLineDataSet);
        }
        LineData mLineData = new LineData(mLineDataSets);
//        if (data.get(0).size()<=4){
        linechart_view.getXAxis().setAxisMaximum(mLineData.getXMax() + 1);
//        }else {
//            linechart_view.getXAxis().setAxisMaximum(mLineData.getXMax());
//        }

        linechart_view.setData(mLineData);
    }


    /**
     * 获取销售额占有率
     */
    private void loadSalesOccupancy() {
        cityDatailActivityPresenter.loadSalesOccupancy(clearUpJSON(1, false));
    }

    //获取销售额占有率成功
    @Override
    public void loadSalesOccupancySuccess(HotBrandCumulativeBean bean) {
        ArrayList<HotBrandCumulativeBean.ReturnValueBean> tempSalesOccupancy = new ArrayList<>();
        if (bean != null) {
            boolean success = bean.isSuccess();
            String message = bean.getMessage();
            if (success) {
                List<HotBrandCumulativeBean.ReturnValueBean> returnValue = bean.getReturnValue();
                if (returnValue != null && returnValue.size() > 0) {
                    tempSalesOccupancy.clear();
                    tempSalesOccupancy.addAll(returnValue);
                }
            }
            dataSalesOccupancy = tempSalesOccupancy;
            if (dataSalesOccupancy.size() == 0) {
                single_lay.setVisibility(View.GONE);
                module3_noinfo.setVisibility(View.VISIBLE);
            } else {
                single_lay.setVisibility(View.VISIBLE);
                module3_noinfo.setVisibility(View.GONE);
                listview_scroll.setAdapter(new OccupancyAdapter());
            }
            loadedType(true, message, 2);
        } else {
            loadedType(false, "", -1);
        }
    }

    //获取销售额占有率失败
    @Override
    public void loadSalesOccupancyFailure() {
        loadedType(false, "", -1);
    }

    //获取销售额占有率失败
    @Override
    public void loadSalesOccupancyFailure(Throwable throwable) {
        if (throwable instanceof ConnectTimeoutException ||
                throwable instanceof SocketTimeoutException) {
            loadingTimeout();
        }
    }


    /**
     * 获取销售走势图
     */
    private void loadSalesTrend() {
        JSONObject object;
        if (isWaterHeater) {
            object = clearUpJSON(2, true);
        } else {
            object = clearUpJSON(2, false);
        }
        cityDatailActivityPresenter.loadSalesTrend(object);
    }

    @Override
    public void loadSalesTrendSuccess(JSONObject jsonObject) {
        ArrayList<ArrayList<HashMap<String, String>>> trendAllData = new ArrayList<>();
        ArrayList<String> brandAllString = new ArrayList<>();
        try {
            if (!TextUitl.isEmpty(jsonObject.toString())) {
                boolean success = jsonObject.getBoolean("success");
                String message = jsonObject.getString("message").trim();
                String returnValue = jsonObject.getString("returnValue").trim();
                if (success && jsonObject.has("returnValue")) {
                    combinedChart_View.clear();
                    if (!TextUitl.isEmpty(returnValue)) {
                        if (!returnValue.equals("{}")) {
                            JSONObject returnValueObject = new JSONObject(returnValue);
                            Iterator iterator = returnValueObject.keys();
                            while (iterator.hasNext()) {
                                String key = iterator.next().toString().trim();
                                String value = returnValueObject.getString(key).trim();
                                brandAllString.add(key);
                                JSONArray array = returnValueObject.getJSONArray(key);
                                ArrayList<HashMap<String, String>> tempBrand = new ArrayList<>();
                                for (int a = 0; a < array.length(); a++) {
                                    JSONObject jsonobject = array.getJSONObject(a);
                                    HashMap<String, String> temp = new HashMap<String, String>();
                                    temp.put("key", jsonobject.get("key").toString().trim());
//                                        Log.e("data","------获取销额数据------"+jsonobject.get("value").toString().trim());
                                    if (measureString.equals("volume")) {
                                        temp.put("value", jsonobject.get("value").toString().trim());
                                    } else {
                                        if (TextUitl.isEmpty(jsonobject.get("value").toString().trim())) {
                                            temp.put("value", jsonobject.get("value").toString().trim());
                                        } else {
                                            temp.put("value", TextUitl.getOutBigData(jsonobject.get("value").toString().trim()));
                                        }
                                    }
                                    tempBrand.add(temp);
                                }
                                trendAllData.add(tempBrand);
                            }

                            if (brandAllString.size() != 0 && brandAllString.get(0).equals("A.O.史密斯")) {
                                Collections.reverse(brandAllString);
                                Collections.reverse(trendAllData);
                            }

                            initCombinedChartData(brandAllString, trendAllData);
                        }
                        if (isWaterHeater) {
                            typeTop50_lay.setVisibility(View.GONE);
                            typeTop50_lay_noinfo.setVisibility(View.GONE);
                            dataTOP50type = new ArrayList<>();
                            typeDatailAdapter = new TypeDatailAdapter();
                            listview.setAdapter(typeDatailAdapter);
                            loading(false, false, false);
                        } else {
                            typeTop50_lay.setVisibility(View.VISIBLE);
                            loadedType(true, message, 3);
                        }

                    } else {
                        loadedType(false, message, -1);
                    }
                } else {
                    loadedType(false, message, -1);
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }

    @Override
    public void loadSalesTrendFailure() {
        loadedType(false, "", -1);
    }

    @Override
    public void loadSalesTrendFailure(Throwable throwable) {
        if (throwable instanceof ConnectTimeoutException ||
                throwable instanceof SocketTimeoutException) {
            loadingTimeout();
        }
    }




    //叠型柱状图
    private void initCombinedChartData(ArrayList<String> brandAllString, ArrayList<ArrayList<HashMap<String, String>>> trendAllData) {
        combinedChart_View.getDescription().setEnabled(false);//不显示表名
        combinedChart_View.setBackgroundColor(Color.WHITE);
        combinedChart_View.setDrawGridBackground(false);
        combinedChart_View.setDrawBarShadow(false);
        combinedChart_View.setScaleYEnabled(false);//Y轴方向上不允许拉伸
        combinedChart_View.setHighlightFullBarEnabled(false);
        combinedChart_View.setDragEnabled(false);
        combinedChart_View.setNoDataText("没有相关数据");
        combinedChart_View.setDrawValueAboveBar(false);//设置数据在上边显示
        combinedChart_View.setTouchEnabled(true); // 设置是否可以触摸
        combinedChart_View.setDragEnabled(true);// 是否可以拖拽
        linechart_view.setFocusableInTouchMode(false);
        combinedChart_View.setScaleEnabled(false);// 是否可以缩放 x和y轴, 默认是true
        combinedChart_View.setPinchZoom(false);  //设置x轴和y轴能否同时缩放。默认是否
        combinedChart_View.setDoubleTapToZoomEnabled(false);//设置是否可以通过双击屏幕放大图表。默认是true
        combinedChart_View.setHighlightPerDragEnabled(false);//能否拖拽高亮线(数据点与坐标的提示线)，默认是true
        combinedChart_View.setDragDecelerationEnabled(false);//拖拽滚动时，手放开是否会持续滚动，默认是true（false是拖到哪是哪，true拖拽之后还会有缓冲）
        // draw bars behind lines设置绘制顺序，重叠部分的图案后绘制的会遮挡先绘制的
        combinedChart_View.setDrawOrder(new AvcCombinedChart.DrawOrder[]{
                AvcCombinedChart.DrawOrder.BAR
//                , CombinedChart.DrawOrder.LINE
        });

        if (trendAllData.size() != 0) {
            combinedChart_View.moveViewToX(getWeekXCoord(trendAllData).size());
        }


        //图例
        Legend l = combinedChart_View.getLegend();
        l.setWordWrapEnabled(true);
        l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
        l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
        l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
        l.setDrawInside(false);

        //设置右边Y轴标签
        combinedChart_View.getAxisRight().setEnabled(false);
        //设置左边Y轴标签
        combinedChart_View.getAxisLeft().setEnabled(false);

        //设置X轴标签
        XAxis xAxis = combinedChart_View.getXAxis();
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        xAxis.setAxisMinimum(0f);
        xAxis.setDrawAxisLine(false);
        xAxis.setDrawGridLines(false);
        xAxis.setGranularity(1f);
        xAxis.setAvoidFirstLastClipping(true);
//        int countNum = trendAllData.get(0).size();
//        if (countNum > 4) {
//            String temp = trendAllData.get(0).get(0).get("key") + "-" + trendAllData.get(0).get(countNum - 1).get("key");
//            final String[] tempMoths = new String[]{temp};
//            xAxis.setValueFormatter(new IndexAxisValueFormatter() {
//                @Override
//                public String getFormattedValue(float value, AxisBase axis) {
//                    int temp = Math.round(value);
//                    if (temp < 1 || temp == tempMoths.length + 1) {
//                        return "";
//                    }
//                    return tempMoths[0];
//                }
//            });
//        } else {
        if (trendAllData.size() != 0) {
            xAxis.setValueFormatter(new IndexAxisValueFormatter() {
                @Override
                public String getFormattedValue(float value, AxisBase axis) {
                    int temp = Math.round(value);
                    if (mMonths.length == 1) {
                        if (temp < 1 || temp == mMonths.length + 1) {
                            return "";
                        }
                        return mMonths[0];
                    } else {
                        if (temp < 1 || temp == mMonths.length + 1) {
                            return "";
                        }
                        if ((value - 1) % mMonths.length < 1) {
                            return mMonths[0];
                        }
                        return mMonths[(int) (value - 1) % mMonths.length];
                    }
                }
            });
        }
//        }


        CombinedData data = new CombinedData();

        if (trendAllData.size() != 0) {
            data.setData(generateBarData(trendAllData));
//        data.setData(generateLineData());
            xAxis.setAxisMaximum(data.getXMax() + 1);//最大宽度另加1个单元格的宽度
//            Log.e("string","--------叠状图获取星期数-------"+mMonths.length);
            if (mMonths.length == 1 || mMonths.length == 2) {
                combinedChart_View.setVisibleXRangeMinimum(2);
            } else if (mMonths.length == 6) {
                combinedChart_View.setVisibleXRangeMinimum(4.8f);
            } else {
                combinedChart_View.setVisibleXRangeMinimum(4);
            }
//            if (mMonths.length == 6){
//                combinedChart_View.setVisibleXRangeMaximum(5f);
//            }else {
            combinedChart_View.setVisibleXRangeMaximum(4.8f);
//            }
            combinedChart_View.resetViewPortOffsets();  //重新设置图表显示的偏移量，自动计算,可取消上面的那个操作
        }

        combinedChart_View.setData(data);
        combinedChart_View.invalidate();


    }


    //获取Y轴最大值
    private float getTrendYMax(ArrayList<ArrayList<HashMap<String, String>>> trendAllData) {
        int itemcount = trendAllData.get(0).size();
        float getTrendYMaxTemp = 0f;
        ArrayList<HashMap<String, String>> hashMaps0 = trendAllData.get(0);
        ArrayList<HashMap<String, String>> hashMaps1 = trendAllData.get(1);
        if (itemcount > 4) {
            float a = 0f;
            float b = 0f;
            for (int index = 0; index < itemcount; index++) {
                HashMap<String, String> hashMap0 = hashMaps0.get(index);
                HashMap<String, String> hashMap1 = hashMaps1.get(index);
                float value0 = 0f;
                float value1 = 0f;
                if (TextUitl.isEmpty(hashMap0.get("value").toString().trim())) {
                    value0 = 0f;
                } else {
                    value0 = Float.valueOf(hashMap0.get("value").toString().trim());
                }
                if (TextUitl.isEmpty(hashMap1.get("value").toString().trim())) {
                    value1 = 0f;
                } else {
                    value1 = Float.valueOf(hashMap1.get("value").toString().trim());
                }
                a += value0;
                b += value1;
            }

            getTrendYMaxTemp = a >= b ? a : b;

        } else {
            for (int index = 0; index < itemcount; index++) {
                HashMap<String, String> hashMap0 = hashMaps0.get(index);
                HashMap<String, String> hashMap1 = hashMaps1.get(index);
                String value0 = hashMap0.get("value").toString().trim();
                String value1 = hashMap1.get("value").toString().trim();
                if (!TextUitl.isEmpty(value0)) {
                    if (getTrendYMaxTemp < Float.valueOf(value0)) {
                        getTrendYMaxTemp = Float.valueOf(value0);
                    }
                }
                if (!TextUitl.isEmpty(value1)) {
                    if (getTrendYMaxTemp < Float.valueOf(value1)) {
                        getTrendYMaxTemp = Float.valueOf(value1);
                    }
                }
            }

        }

        return getTrendYMaxTemp;
    }


    private List<Float> lineDatas;//线图数据源
    //堆图数据源
//    private LineData generateLineData() {
//        lineDatas = new ArrayList<>();
//        for (int i = 0; i < barDatas.size(); i++) {
//
//            lineDatas.add(barDatas.get(i)[0] / (plus(barDatas.get(i))) * 100);
//
//        }
//
//        LineData d = new LineData();
//
//        ArrayList<Entry> entries = new ArrayList<Entry>();
//
//        //传入数据
//        for (int index = 0; index < itemcount; index++)
//            entries.add(new Entry(index + 1, lineDatas.get(index)));
//
//        LineDataSet set = new LineDataSet(entries, "完成率");
//        set.setColor(getResources().getColor(R.color.red));
//        set.setLineWidth(2.5f);
//        set.setCircleColor(Color.rgb(240, 238, 70));
//        set.setCircleRadius(5f);
//        set.setFillColor(Color.rgb(240, 238, 70));
//        set.setMode(LineDataSet.Mode.LINEAR);
//        set.setDrawValues(true);
//        set.setValueTextSize(10f);
//        set.setValueTextColor(getResources().getColor(R.color.black));//设置内容字体颜色
//
//        set.setAxisDependency(YAxis.AxisDependency.RIGHT);//以右边Y轴的标签绘制
//        d.addDataSet(set);
////        MyAxisValueFormatter format = new MyAxisValueFormatter();
////        d.setValueFormatter(format);
//
//        return d;
//    }


    private String[] mMonths;

    @SuppressWarnings("deprecation")
    //叠状图数据
    private BarData generateBarData(ArrayList<ArrayList<HashMap<String, String>>> trendAllData) {
        List<float[]> barDatas = new ArrayList<>();
        int itemcount = trendAllData.get(0).size();
        mMonths = new String[itemcount];//X轴标签
        ArrayList<BarEntry> entries = new ArrayList<>();
        ArrayList<HashMap<String, String>> hashMaps0 = trendAllData.get(0);
        ArrayList<HashMap<String, String>> hashMaps1 = trendAllData.get(1);
//        if (itemcount > 4) {
//            float a = 0f;
//            float b = 0f;
//            for (int i = 0; i < itemcount; i++) {
//                HashMap<String, String> hashMap0 = trendAllData.get(0).get(i);
//                HashMap<String, String> hashMap1 = trendAllData.get(1).get(i);
//                mMonths[i] = hashMap0.get("key").toString().trim();
//                float value0 = 0f;
//                float value1 = 0f;
//                if (!TextUitl.isEmpty(hashMap0.get("value").toString().trim())) {
//                    value0 = Float.valueOf(hashMap0.get("value").toString().trim());
//                }
//                if (!TextUitl.isEmpty(hashMap1.get("value").toString().trim())) {
//                    value1 = Float.valueOf(hashMap1.get("value").toString().trim());
//                }
//                a += value0;
//                b += value1;
//            }
//            barDatas.add(new float[]{b, a});
//
//            // stacked
//            entries.add(new BarEntry(1, barDatas.get(0)));
//
//        } else {
        for (int index = 0; index < itemcount; index++) {
            HashMap<String, String> hashMap0 = trendAllData.get(0).get(index);
            HashMap<String, String> hashMap1 = trendAllData.get(1).get(index);

            mMonths[index] = hashMap0.get("key").toString().trim();
            float value0 = 0f;
            float value1 = 0f;
            if (!TextUitl.isEmpty(hashMap0.get("value").toString().trim())) {
                value0 = Float.valueOf(hashMap0.get("value").toString().trim());
            }
            if (!TextUitl.isEmpty(hashMap1.get("value").toString().trim())) {
                value1 = Float.valueOf(hashMap1.get("value").toString().trim());
            }
            barDatas.add(new float[]{value1, value0});
            entries.add(new BarEntry(index + 1, barDatas.get(index)));
        }

//        }
        BarDataSet set = new BarDataSet(entries, "");
        if (measureString.equals("amount")) {
            set.setStackLabels(new String[]{"A.O史密斯", cityString + "    单位：元"});
        } else {
            set.setStackLabels(new String[]{"A.O史密斯", cityString + "    单位：台"});
        }
        set.setColors(new int[]{getResources().getColor(R.color.blue_ao), getResources().getColor(R.color.blue_nationwide)});
        set.setValueTextColor(getResources().getColor(R.color.text_color));
        set.setValueTextSize(8f);


        if (measureString.equals("amount")) {
            set.setValueFormatter(new IValueFormatter() {
                @Override
                public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
                    if (value >= 100000000f) {
                        return TextUitl.retainTwoDecimalsString(value / 100000000) + "亿";
                    } else if (value < 100000000f && value >= 10000f) {
                        return TextUitl.retainTwoDecimalsString(value / 10000) + "万";
                    } else {
                        if (TextUitl.isEmpty(value + "") || (value + "").equals("0.0")) {
                            return 0 + "";
                        } else {
                            return TextUitl.retainTwoDecimalsString(value) + "";
                        }
                    }
                }
            });
        } else {
            set.setValueFormatter(new IValueFormatter() {
                @Override
                public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
                    if (value >= 10000) {
                        return TextUitl.retainTwoDecimals(value / 10000 + "") + "万";
                    } else {
                        if (TextUitl.isEmpty(value + "") || (value + "").equals("0.0")) {
                            return 0 + "";
                        } else {
                            return Math.round(value) + "";
                        }
                    }
                }
            });
        }
//        set.setAxisDependency(YAxis.AxisDependency.LEFT);//以左边Y轴的标签绘制

        BarData d = new BarData(set);
        float barWidth = 0.3f;//x2 dataset
//        if (itemcount == 1) {
//            barWidth = 0.3f;
//        } else if (itemcount == 2) {
//            barWidth = 0.3f;
//        } else if (itemcount > 4) {
//            barWidth = 0.2f;
//        }
//        Log.e("string","--------柱状图宽度--------"+barWidth);
        d.setBarWidth(barWidth);
        return d;
    }

    /**
     * 获取TOP50机型技术类型
     */
    private void loadTOP50Skilltype() {
        loading(false, true, false);
        cityDatailActivityPresenter.loadTOP50Skilltype(categoryString, "productTechs");
    }

    //获取TOP50机型技术类型成功
    @Override
    public void loadTop50SkilltypeSuccess(TechnologyBean bean) {
        if (bean != null) {
            boolean success = bean.isSuccess();
            String message = bean.getMessage();
            List<TechnologyBean.ReturnValueBean> returnValue = bean.getReturnValue();
            if (success) {
                if (returnValue != null && returnValue.size() > 0) {
                    dataPopup = returnValue;
                    initpopupWindows();
                    loadedType(true, message, 4);
                } else {
                    loadedType(false, message, -1);
                }
            } else {
                loadedType(false, message, -1);
            }
        }
        loading(false, false, false);
    }

    //获取TOP50机型技术类型失败
    @Override
    public void loadTop50SkilltypeFailure() {
        loadedType(false, "", -1);
        loading(false, false, false);
    }

    //获取TOP50机型技术类型失败
    @Override
    public void loadTop50SkilltypeFailure(Throwable throwable) {
        if (throwable instanceof ConnectTimeoutException ||
                throwable instanceof SocketTimeoutException) {
            loadingTimeout();
            loading(false, false, false);
        }
    }




    /**
     * 获取TOP50机型详情
     */
    private void loadTOP50type() {
        cityDatailActivityPresenter.loadTOP50type(clearUpJSON(3, true));
    }

    @Override
    public void loadTOP50typeSuccess(DetailsBean bean) {
        boolean success = bean.isSuccess();
        String message = bean.getMessage();
        if (success) {
            if (bean != null) {
                List<DetailsBean.ReturnValueBean> returnValue = bean.getReturnValue();
                dataTOP50type = returnValue;
                if (dataTOP50type == null || dataTOP50type.size() == 0) {
                    typeTop50_lay_noinfo.setVisibility(View.VISIBLE);
                } else {
                    typeTop50_lay_noinfo.setVisibility(View.GONE);
                    typeDatailAdapter = new TypeDatailAdapter();
                    listview.setAdapter(typeDatailAdapter);
                }
            } else {
                loadedType(false, message, -1);
            }
        } else {
            loadedType(false, message, -1);
        }
        loading(false, false, false);
    }

    @Override
    public void loadTOP50typeFailure() {
        loadedType(false, "", -1);
        loading(false, false, false);
    }

    @Override
    public void loadTOP50typeFailure(Throwable throwable) {
        if (throwable instanceof ConnectTimeoutException ||
                throwable instanceof SocketTimeoutException) {
            loadingTimeout();
            loading(false, false, false);
        }
    }

    private void loadedType(boolean isSuccess, String message, int number) {
        if (isSuccess) {
            if (number == 0) {
                loadHotBrandSales();
            } else if (number == 1) {
                loadSalesOccupancy();
            } else if (number == 2) {
                loadSalesTrend();
            } else if (number == 3) {
                loadTOP50Skilltype();
            } else if (number == 4) {
                loadTOP50type();
            }
        } else {
            if (message.equals("ok!")) {
                loading(true, false, true);
                return;
            }
            loading(true, false, false);
        }

    }

    @SuppressWarnings("deprecation")
    private void initpopupWindows() {
        View single_listviewPopup = LayoutInflater.from(this).inflate(R.layout.single_listviewselectpopup, null);
//        single_listviewPopup.setBackgroundResource(R.mipmap.bg_popup_window);
        ListView listViewPopup = (ListView) single_listviewPopup.findViewById(R.id.listview);
        TextView teach_ensure = (TextView) single_listviewPopup.findViewById(R.id.teach_ensure);
        popupWindow = new PopupWindow(single_listviewPopup, ScreenUtils.getScreenWidth(this) / 4, LinearLayout.LayoutParams.WRAP_CONTENT, true);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        popupWindow.setTouchable(true);
        popupWindow.setFocusable(true);
        popupWindow.setOutsideTouchable(true);
        module_typeString = "技术筛选";
        final TypeTOP50DatailAdapter adapter = new TypeTOP50DatailAdapter(dataPopup);
        listViewPopup.setAdapter(adapter);

        listViewPopup.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (dataPopupCheck.contains(dataPopup.get(position).getValue())) {
                    dataPopupCheck.remove(dataPopup.get(position).getValue());
                } else {
                    dataPopupCheck.add(dataPopup.get(position).getValue());
                }
                adapter.notifyDataSetChanged();
            }
        });


        teach_ensure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (dataPopupCheck.size() > 1) {
                    module_type.setText("多选");
                } else {
                    if (dataPopupCheck.size() == 0) {
                        module_type.setText("技术筛选");
                    } else {
                        module_type.setText(dataPopupCheck.get(0));
                    }

                }
                popupWindow.dismiss();
//                load(false);
                loadTOP50Skilltype();
//                adapter.notifyDataSetChanged();
            }
        });

    }

    @Override
    public void onChartGestureStart(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {

    }

    @Override
    public void onChartGestureEnd(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {

    }

    @Override
    public void onChartLongPressed(MotionEvent me) {

    }

    @Override
    public void onChartDoubleTapped(MotionEvent me) {

    }

    @Override
    public void onChartSingleTapped(MotionEvent me) {

    }

    @Override
    public void onChartFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY) {

    }

    @Override
    public void onChartScale(MotionEvent me, float scaleX, float scaleY) {

    }

    @Override
    public void onChartTranslate(MotionEvent me, float dX, float dY) {

    }

    @Override
    public void onValueSelected(Entry e, Highlight h) {

    }

    @Override
    public void onNothingSelected() {

    }


    //占比率适配器
    private class OccupancyAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return dataSalesOccupancy.size();
        }

        @Override
        public Object getItem(int position) {
            return dataSalesOccupancy.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @SuppressWarnings("deprecation")
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolderOccupancy vHolder = null;
            if (convertView == null) {
                convertView = LayoutInflater.from(CityDatail_Activity.this).inflate(R.layout.item_selecttimetype, null);
                vHolder = new ViewHolderOccupancy();
                vHolder.item_selecttimetypetitle = (RelativeLayout) convertView.findViewById(item_selecttimetypetitle);
                vHolder.user_line = (ImageView) convertView.findViewById(R.id.user_line);
                vHolder.brand = (TextView) convertView.findViewById(R.id.brand);
                vHolder.occupancy = (TextView) convertView.findViewById(R.id.occupancy);
                vHolder.on_yearonyearbasis = (TextView) convertView.findViewById(R.id.on_yearonyearbasis);
                convertView.setTag(vHolder);
            } else {
                vHolder = (ViewHolderOccupancy) convertView.getTag();
            }

            if (position == 0) {
                vHolder.item_selecttimetypetitle.setVisibility(View.VISIBLE);
            } else {
                vHolder.item_selecttimetypetitle.setVisibility(View.GONE);
            }

            HotBrandCumulativeBean.ReturnValueBean returnValueBean = dataSalesOccupancy.get(position);

            vHolder.brand.setText(returnValueBean.getBrand());
            vHolder.occupancy.setText(TextUitl.retainTwoDecimalsFloat(returnValueBean.getMarket_share() + "") + "%");
            Drawable drawable = null;

            if (TextUitl.isEmpty(returnValueBean.getBasis_ratio() + "")) {
                vHolder.on_yearonyearbasis.setTextColor(getResources().getColor(R.color.text_one));
                drawable = getResources().getDrawable(R.drawable.square_white);
                vHolder.on_yearonyearbasis.setText("--");

            } else if ("0".equals(returnValueBean.getBasis_ratio()) || "0.0".equals(returnValueBean.getBasis_ratio())) {
                vHolder.on_yearonyearbasis.setTextColor(getResources().getColor(R.color.text_one));
                drawable = getResources().getDrawable(R.drawable.square_white);
                vHolder.on_yearonyearbasis.setText(TextUitl.retainTwoDecimalsFloat(returnValueBean.getBasis_ratio() + "") + "%");
            } else {
                if (TextUitl.isUp(returnValueBean.getBasis_ratio() + "")) {
                    drawable = getResources().getDrawable(R.drawable.data_rise);
                    vHolder.on_yearonyearbasis.setTextColor(getResources().getColor(R.color.green));
                } else {
                    drawable = getResources().getDrawable(R.drawable.data_decline);
                    vHolder.on_yearonyearbasis.setTextColor(getResources().getColor(R.color.red));
                }
                vHolder.on_yearonyearbasis.setText(TextUitl.retainTwoDecimalsFloat(returnValueBean.getBasis_ratio() + "") + "%");
            }
            drawable.setBounds(0, 0, 20, 25);
            vHolder.on_yearonyearbasis.setCompoundDrawables(drawable, null, null, null);

            return convertView;
        }

    }


    private class ViewHolderOccupancy {
        RelativeLayout item_selecttimetypetitle;
        ImageView user_line;
        TextView brand;
        TextView occupancy;
        TextView on_yearonyearbasis;


    }

    //TOP50技术选择适配器
    private class TypeTOP50DatailAdapter extends BaseAdapter {
        protected List<TechnologyBean.ReturnValueBean> data;
        private int selectPosition;

        public TypeTOP50DatailAdapter(List<TechnologyBean.ReturnValueBean> data) {
            super();
            this.data = data;
            this.selectPosition = -1;
        }

        public void setData(ArrayList<TechnologyBean.ReturnValueBean> data) {
            this.data = data;
        }

        private int count = -1;


        @Override
        public int getCount() {
            if (data == null) {
                return 0;
            }
            int getCount = data.size();
            return count == -1 ? getCount : Math.min(getCount, count);
        }

        @Override
        public Object getItem(int position) {

            return data == null ? new Object() : data.get(position);
        }

        @Override
        public long getItemId(int position) {

            return position;
        }

        @SuppressWarnings("deprecation")
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolderType vHolder = null;
            if (convertView == null) {
                convertView = LayoutInflater.from(CityDatail_Activity.this).inflate(R.layout.single_textviewpopup, null);
                vHolder = new ViewHolderType();
                vHolder.single_textview = (TextView) convertView.findViewById(R.id.single_textview);
                convertView.setTag(vHolder);
            } else {
                vHolder = (ViewHolderType) convertView.getTag();
            }

            vHolder.single_textview.setText(data.get(position).getValue());
            if (isExistString(data.get(position).getValue())) {
                vHolder.single_textview.setTextColor(getResources().getColor(R.color.blue));
            } else {
                vHolder.single_textview.setTextColor(getResources().getColor(R.color.black));
            }

            return convertView;

        }

    }

    private boolean isExistString(String string) {
        if (dataPopupCheck.size() == 0) {
            return false;
        }
        for (int i = 0, j = dataPopupCheck.size(); i < j; i++) {
            if (dataPopupCheck.get(i).equals(string)) {
                return true;
            }
        }
        return false;
    }


    private class ViewHolderType {
        TextView single_textview;
    }


    //TOP50适配器
    private class TypeDatailAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return dataTOP50type.size();
        }

        @Override
        public Object getItem(int position) {
            return dataTOP50type.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @SuppressWarnings("deprecation")
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder vHolder = null;
            if (convertView == null) {
                convertView = LayoutInflater.from(CityDatail_Activity.this).inflate(R.layout.item_typeinfo, null);
                vHolder = new ViewHolder();
                vHolder.item_typeinfotitle = (RelativeLayout) convertView.findViewById(R.id.item_typeinfotitle);
                vHolder.typeinfo_ranking = (TextView) convertView.findViewById(R.id.typeinfo_ranking);
                vHolder.typeinfo_phonetype = (TextView) convertView.findViewById(R.id.typeinfo_phonetype);
                vHolder.typeinfo_brand = (TextView) convertView.findViewById(R.id.typeinfo_brand);
                vHolder.typeinfo_occupancy = (TextView) convertView.findViewById(R.id.typeinfo_occupancy);
                vHolder.typeinfo_averageprice = (TextView) convertView.findViewById(R.id.typeinfo_averageprice);
                vHolder.tag_lay = (LinearLayout) convertView.findViewById(R.id.tag_lay);
                vHolder.relativeratio_occupancy = (TextView) convertView.findViewById(R.id.relativeratio_occupancy);
                vHolder.relativeratio_average = (TextView) convertView.findViewById(R.id.relativeratio_average);

                convertView.setTag(vHolder);
            } else {
                vHolder = (ViewHolder) convertView.getTag();
            }


            if (position == 0) {
                vHolder.item_typeinfotitle.setVisibility(View.VISIBLE);
            } else {
                vHolder.item_typeinfotitle.setVisibility(View.GONE);
            }

            DetailsBean.ReturnValueBean returnValueBean = dataTOP50type.get(position);

            if ("A.O.史密斯".equals(returnValueBean.getBrand())) {
                vHolder.typeinfo_ranking.setTextColor(getResources().getColor(R.color.red));
                vHolder.typeinfo_phonetype.setTextColor(getResources().getColor(R.color.red));
                vHolder.typeinfo_brand.setTextColor(getResources().getColor(R.color.red));
                vHolder.typeinfo_occupancy.setTextColor(getResources().getColor(R.color.red));
                vHolder.typeinfo_averageprice.setTextColor(getResources().getColor(R.color.red));
            } else {
                vHolder.typeinfo_ranking.setTextColor(getResources().getColor(R.color.text_color));
                vHolder.typeinfo_phonetype.setTextColor(getResources().getColor(R.color.text_color));
                vHolder.typeinfo_brand.setTextColor(getResources().getColor(R.color.text_color));
                vHolder.typeinfo_occupancy.setTextColor(getResources().getColor(R.color.text_color));
                vHolder.typeinfo_averageprice.setTextColor(getResources().getColor(R.color.text_color));
            }

            if (TextUitl.isEmpty(returnValueBean.getRank() + "")) {
                vHolder.typeinfo_ranking.setText("暂无排名");
            } else {
                vHolder.typeinfo_ranking.setText(returnValueBean.getRank() + "");
            }
            vHolder.typeinfo_phonetype.setText(returnValueBean.getModel());
            vHolder.typeinfo_brand.setText(returnValueBean.getBrand());
            vHolder.typeinfo_occupancy.setText(TextUitl.retainTwoDecimalsFloat(returnValueBean.getMarketShare() + "") + " %");
            vHolder.typeinfo_averageprice.setText(returnValueBean.getAvgPrice() + "");

            if(null== returnValueBean.getProductTechs() || "".equals(returnValueBean.getProductTechs())){
                vHolder.tag_lay.setVisibility(View.GONE);
            }else{
                if (TextUitl.isEmpty(returnValueBean.getProductTechs())) {
                    vHolder.tag_lay.setVisibility(View.GONE);
                } else {
                    String[] array = returnValueBean.getProductTechs().split(",");
                    vHolder.tag_lay.removeAllViews();
                    for (int i = 0, j = array.length; i < j; i++) {
                        if (TextUitl.isEmpty(array[i]) || array[i].equals("{}")) {
                            vHolder.tag_lay.setVisibility(View.GONE);
                        } else {
                            vHolder.tag_lay.setVisibility(View.VISIBLE);
                            tagView = LayoutInflater.from(CityDatail_Activity.this).inflate(R.layout.tag_type, null);
                            TextView textView = (TextView) tagView.findViewById(item_name);
                            if ("A.O.史密斯".equals(returnValueBean.getBrand())) {
                                if (isExistTeachString(array[i])) {
                                    textView.setBackgroundResource(R.drawable.tagdatail_blue);
                                    textView.setTextColor(getResources().getColor(R.color.blue));
                                } else {
                                    textView.setBackgroundResource(R.drawable.tagdatail_red);
                                    textView.setTextColor(getResources().getColor(R.color.red));
                                }
                            } else {
                                if (isExistTeachString(array[i])) {
                                    textView.setBackgroundResource(R.drawable.tagdatail_blue);
                                    textView.setTextColor(getResources().getColor(R.color.blue));
                                } else {
                                    textView.setBackgroundResource(R.drawable.tagdatial_gray);
                                    textView.setTextColor(getResources().getColor(R.color.text_one));
                                }
                            }
                            textView.setText(array[i]);
                            vHolder.tag_lay.addView(tagView);

                        }
                    }
                }
            }

            //占有率环比
            Drawable drawable_occupancy = null;
            String shareRelativeRatio = returnValueBean.getShareRelativeRatio() + "";
            if (TextUitl.isEmpty(shareRelativeRatio)) {
                vHolder.relativeratio_occupancy.setTextColor(getResources().getColor(R.color.text_one));
                drawable_occupancy = getResources().getDrawable(R.drawable.square_white);
                vHolder.relativeratio_occupancy.setText("--");
            } else if ("0".equals(shareRelativeRatio) || "0.0".equals(shareRelativeRatio)) {
                vHolder.relativeratio_occupancy.setTextColor(getResources().getColor(R.color.text_one));
                drawable_occupancy = getResources().getDrawable(R.drawable.square_white);
                vHolder.relativeratio_occupancy.setText(TextUitl.retainTwoDecimalsFloat(shareRelativeRatio) + "%");
            } else {
                if (TextUitl.isUp(shareRelativeRatio)) {
                    drawable_occupancy = getResources().getDrawable(R.drawable.data_rise);
                    vHolder.relativeratio_occupancy.setTextColor(getResources().getColor(R.color.green));
                } else {
                    drawable_occupancy = getResources().getDrawable(R.drawable.data_decline);
                    vHolder.relativeratio_occupancy.setTextColor(getResources().getColor(R.color.red));
                }
                vHolder.relativeratio_occupancy.setText(TextUitl.retainTwoDecimalsFloat(shareRelativeRatio) + "%");
            }
            drawable_occupancy.setBounds(0, 0, 20, 22);
            vHolder.relativeratio_occupancy.setCompoundDrawables(null, null, drawable_occupancy, null);

            //均价环比
            Drawable drawable_average = null;
            if(null == returnValueBean.getAvgPriceRelativeRatio() || "".equals(returnValueBean.getAvgPriceRelativeRatio())){
                vHolder.relativeratio_average.setTextColor(getResources().getColor(R.color.text_one));
                drawable_average = getResources().getDrawable(R.drawable.square_white);
                vHolder.relativeratio_average.setText("--");
            }else{
                String avgPriceRelativeRatio = returnValueBean.getAvgPriceRelativeRatio() + "";
                if (TextUitl.isEmpty(avgPriceRelativeRatio)) {
                    vHolder.relativeratio_average.setTextColor(getResources().getColor(R.color.text_one));
                    drawable_average = getResources().getDrawable(R.drawable.square_white);
                    vHolder.relativeratio_average.setText("--");

                } else if ("0".equals(avgPriceRelativeRatio) || "0.0".equals(avgPriceRelativeRatio)) {
                    vHolder.relativeratio_average.setTextColor(getResources().getColor(R.color.text_one));
                    drawable_average = getResources().getDrawable(R.drawable.square_white);
                    vHolder.relativeratio_average.setText(avgPriceRelativeRatio);
                } else {
                    if (TextUitl.isUp(avgPriceRelativeRatio)) {
                        drawable_average = getResources().getDrawable(R.drawable.data_rise);
                        vHolder.relativeratio_average.setTextColor(getResources().getColor(R.color.green));
                    } else {
                        drawable_average = getResources().getDrawable(R.drawable.data_decline);
                        vHolder.relativeratio_average.setTextColor(getResources().getColor(R.color.red));
                    }
                    vHolder.relativeratio_average.setText(TextUitl.retainRound(avgPriceRelativeRatio));
                }
            }
            drawable_average.setBounds(0, 0, 20, 22);
            vHolder.relativeratio_average.setCompoundDrawables(null, null, drawable_average, null);
            return convertView;
        }
    }

    private boolean isExistTeachString(String string) {
        if (dataPopupCheck.size() == 0) {
            return false;
        }
        for (int i = 0, j = dataPopupCheck.size(); i < j; i++) {
            if (dataPopupCheck.get(i).equals(string)) {
                return true;
            }
        }
        return false;
    }


    private class ViewHolder {
        RelativeLayout item_typeinfotitle;
        TextView typeinfo_ranking;
        TextView typeinfo_phonetype;
        TextView typeinfo_brand;
        TextView typeinfo_occupancy;
        TextView typeinfo_averageprice;
        LinearLayout tag_lay;

        TextView relativeratio_occupancy;
        TextView relativeratio_average;
    }


    private void initTouchListener() {
        listview.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        mFirstY = event.getY();
                        break;
                    case MotionEvent.ACTION_MOVE:
                        mCurrentY = event.getY();
                        if (mCurrentY - mFirstY > mTouchSlop) {
                            direction = 0;// down
                        } else if (mFirstY - mCurrentY > mTouchSlop) {
                            direction = 1;// up
                        }
                        if (direction == 1) {

//                            //下滑todo
//                            if (selectdatail.getVisibility() == View.VISIBLE) {
//                                Animation top_out_animation = AnimationUtils.loadAnimation(CityDatail_Activity.this, R.anim.exit_dropup);
//                                selectdatail.startAnimation(top_out_animation);
//                                selectdatail.setVisibility(View.GONE);
//                            }

                            //上滑todo
                            if (selectdatail.getVisibility() == View.GONE) {
                                Animation top_inan_imation = AnimationUtils.loadAnimation(CityDatail_Activity.this, R.anim.enter_dropdown);
                                selectdatail.startAnimation(top_inan_imation);
                                selectdatail.setVisibility(View.VISIBLE);
                            }

                        } else if (direction == 0) {
//                            //上滑todo
//                            if (selectdatail.getVisibility() == View.GONE) {
//                                Animation top_inan_imation = AnimationUtils.loadAnimation(CityDatail_Activity.this, R.anim.enter_dropdown);
//                                selectdatail.startAnimation(top_inan_imation);
//                                selectdatail.setVisibility(View.VISIBLE);
//                            }

                            //下滑todo
                            if (selectdatail.getVisibility() == View.VISIBLE) {
                                Animation top_out_animation = AnimationUtils.loadAnimation(CityDatail_Activity.this, R.anim.exit_dropup);
                                selectdatail.startAnimation(top_out_animation);
                                selectdatail.setVisibility(View.GONE);
                            }

                        }
                        break;
                    case MotionEvent.ACTION_UP:
                        break;
                }
                return false;
            }
        });

    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        this.unregisterReceiver(myReceiver);
    }

    @Override
    public void onBackPressed() {
        if (popupWindow != null && popupWindow.isShowing()) {
            popupWindow.dismiss();
        } else {
            AppActivityManager.getAppManager().finishActivity(this);
        }
    }


}
